from typing import List
from pydantic import BaseSettings, Field


class AppSettings(BaseSettings):
    host: str = Field('0.0.0.0', title='主机')
    port: int = Field(9000, title='端口')
    blueprints: List[str] = Field(['heartbeat', 'lottery', 'frequency', 'prediction'], title='蓝图')


class MongoSettings(BaseSettings):
    db_uri: str = Field('mongodb://localhost:27017/test')
    db_lottery: str = Field('lottery')
    col_lottery: str = Field('lottery')
    col_frequency: str = Field('frequency')
    col_prediction: str = Field('prediction')


class LogSettings(BaseSettings):
    log_name: str = Field('lottery', title='log名')
    log_level: str = Field('INFO', title='log等奖')
    log_format: str = Field('%(asctime)s - %(name)s - %(levelname)s - %(message)s', title='log样式')


class OpenApiSettings(BaseSettings):
    api_refer: str = Field('http://www.cwl.gov.cn/kjxx/ssq/')
    api_phase_code: str = Field('http://www.cwl.gov.cn/cwl_admin/kjxx/findKjxx/forIssue?name=ssq&code={}')
    api_phase_history: str = Field('http://www.cwl.gov.cn/cwl_admin/kjxx/findDrawNotice?name=ssq&issueCount=1')


class SchedulerSettings(BaseSettings):
    jobs: List[dict] = Field([
        {
            'id': 'scrapy_lottery',
            'func': 'app.jobs:scrapy_latest_lottery',
            'trigger': 'cron',
            'day_of_week': 'tue, thu, sun',
            'hour': '21,22,23',
            'minute': 20,
            'timezone': 'Asia/Shanghai'
        },
        {
            'id': 'caculate_frequency',
            'func': 'app.jobs:caculate_frequency_latest',
            'trigger': 'cron',
            'day_of_week': 'tue, thu, sun',
            'hour': '22,23',
            'minute': 30,
            'timezone': 'Asia/Shanghai'
        },
        {
            'id': 'caculate_accuracy',
            'func': 'app.jobs:caculate_accuracy_latest',
            'trigger': 'cron',
            'day_of_week': 'tue, thu, sun',
            'hour': '22,23',
            'minute': 50,
            'timezone': 'Asia/Shanghai'
        }
    ])


app_settings = AppSettings()
mongo_settings = MongoSettings()
log_settings = LogSettings()
openapi_settings = OpenApiSettings()
scheduler_settings = SchedulerSettings()
